package com.yycx.module.bus.provider.service.hy.impl;

import cn.hutool.core.map.MapUtil;
import com.yycx.common.base.entity.EntityMap;

import java.util.List;
import java.util.Map;

/**
 * erp查询父类
 */
public abstract class BaseErpServiceImp {
    /**
     * 获取返回对象
     *
     * @param params
     * @param list
     * @param total
     * @return
     */
    public EntityMap getPageModel(Map params, List<EntityMap> list, int total) {
        int limit = MapUtil.getInt(params, "limit");
        int page = MapUtil.getInt(params, "page");
        int pages = Math.toIntExact(total / limit);
        EntityMap pageModel = new EntityMap();
        pageModel.put("size", list.size());
        pageModel.put("total", total);
        pageModel.put("current", page);
        pageModel.put("pages", pages);
        pageModel.put("records", list);
        return pageModel;
    }

    /**
     * 初始化分页参数
     *
     * @param params
     * @return
     */
    public void initParams(Map params) {
        int limit = MapUtil.getInt(params, "limit");
        int page = MapUtil.getInt(params, "page");
        int endLimit = limit * (page - 1);
        params.put("endLimit", endLimit);
    }
}
